package com.baizan.daka.ui.activity

import android.app.Dialog
import android.content.Context
import android.content.Intent
import android.widget.TextView
import com.baizan.daka.base.BaseListActivity
import com.baizan.daka.mvp.model.bean.BannerBean
import com.baizan.daka.mvp.model.bean.PackageBean
import com.baizan.daka.net.BasePageResponse
import com.baizan.daka.ui.adapter.PackageAdapter
import com.baizan.daka.ui.contract.PackageContract
import com.baizan.daka.ui.dialog.ButtomDialog
import com.baizan.daka.ui.presenter.PackagePresenter
import com.dianzan.daka.R
import kotlinx.android.synthetic.main.act_flow_package.*

class FlowPackageActivity : BaseListActivity<PackagePresenter, PackageAdapter>(), PackageContract.View {
    var list: List<PackageBean>? = null
    var titleList: Array<String>? = null
    var selectIndex: Int = 0

    companion object {
        fun start(context: Context) {
            var intent = Intent(context, FlowPackageActivity::class.java)
            context.startActivity(intent)
        }
    }

    override fun initPresenter(): PackagePresenter = PackagePresenter(this)

    override fun layoutId(): Int = R.layout.act_flow_package


    override fun initView() {
//        package_type_value.setOnClickListener {
//            it as TextView
//            val textView = it
//            titleList?.let {
//                val builder: ButtomDialog.Builder = ButtomDialog.Builder(this)
//                builder.setContentData(it)
//                builder.setListener(object : ButtomDialog.OnItemSelectListener {
//
//                    override fun OnItemSelected(dialog: Dialog, position: Int, title: String?) {
//                        when (position) {
//                            it.size+1 -> dialog.dismiss()
//                            else -> {
//                                textView.text = title
//                                selete(position)
//                                dialog.dismiss()
//                            }
//                        }
//                    }
//                })
//                builder.Build().show()
//            }
//        }
//        submit_bt.setOnClickListener {
//            mContext?.let {
//                val context = it
//                list?.let {
//                    PayActivity.startPayPackage(context, it.get(selectIndex))
//                }
//
//            }
//
//        }
    }

    override fun start() {
        presenter?.loadList(1)
    }

//    private fun selete(index: Int) {
//        selectIndex = index
//        list?.let {
//            var packageBean = it.get(index)
//            package_type_value.text = packageBean.packageName
//            package_name_value.text = packageBean.packageName
////            star_type_value.text = packageBean.
//            money_value.text = "￥${packageBean.unitPrice}元"
//            star_number_value.text = "${packageBean.likeNumber}条"
//            package_des_value.text = packageBean.packageDesc
//            package_money_value.text = "${packageBean.packagePrice}元"
//        }
//    }

    override fun loadListSuccess(data: BasePageResponse<PackageBean>) {
//        val list = data.records
//        this.list = list
//        if (list.isEmpty()) return
//        var arrayList = ArrayList<String>()
//        for (item in list) {
//            arrayList.add(item.packageName)
//        }
//        this.titleList = arrayList.toTypedArray()
//        selete(0)
        adapter?.setNewData(data.records)
    }

    override fun loadListFail(fail: String) {
    }

    override fun loadBannerSuccess(data: List<BannerBean>) {

    }

    override fun loadBannerFail() {
    }

    override fun initAdapter(): PackageAdapter = PackageAdapter()
}